<template>
    <div class="page-container-inner">
        <h4 class="text-lg p-1 pb-0">{{ $t('system.testing.transfer-in.title') }}</h4>
        <div class="py-8 pr-28">
            <el-form label-width="180px" :model="dataCache" style="max-width: 460px">
                <el-form-item :label="$t('system.testing.transfer-in.plat_code')" required
                              :error="Boolean(msg.errors['plat_code']) ? msg.errors['plat_code'][0] : ''">
                    <component-page-org-tree-option v-model="dataCache.plat_code" block></component-page-org-tree-option>
                </el-form-item>
                <el-form-item :label="$t('system.testing.transfer-in.account_id')" required
                              :error="Boolean(msg.errors['account_id']) ? msg.errors['account_id'][0] : ''">
                    <el-input v-model="dataCache.account_id"></el-input>
                </el-form-item>
                <el-form-item :label="$t('system.testing.transfer-in.currency')" required
                              :error="Boolean(msg.errors['currency']) ? msg.errors['currency'][0] : ''">
                    <component-page-option-currency v-model="dataCache.currency" :multiple="false" class="block"></component-page-option-currency>
                </el-form-item>
                <el-form-item :label="$t('system.testing.transfer-in.amount')" required
                              :error="Boolean(msg.errors['amount']) ? msg.errors['amount'][0] : ''">
                    <el-input v-model.number="dataCache.amount" type="number"></el-input>
                </el-form-item>
            </el-form>
            <!--操作-->
            <el-form label-width="180px">
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">{{ $t('system.testing.transfer-in.submit') }}</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            dataCache: {
                plat_code: '',
                account_id: '',
                currency: '',
                amount: null,
            },
            msg: {
                code: 200,
                message: '',
                errors: {},
            },
        }
    },
    methods: {
        initMsg() {
            this.msg.code = 200;
            this.msg.message = '';
            this.msg.errors = {};
        },
        onSubmit() {
            this.initMsg();
            // loading 状态 start
            let loading = this.$loading();
            // 保存数据
            axios.post('/system/testing/order/transfer_in', this.dataCache).then((response) => {
                // loading 状态 close
                loading.close();
                // 逻辑处理
                if (response.data.resp_msg.code == 200) {
                    this.$message({
                        type: 'success',
                        message: this.$t('messages.succeeded', {status: this.$t('system.testing.transfer-in.submit')}),
                        showClose: true
                    });
                } else if (_.includes([42000], response.data.resp_msg.code)) {
                    this.$message({
                        type: 'error',
                        message: response.data.resp_msg.message,
                        showClose: true
                    });
                    this.msg = response.data.resp_msg;
                } else {
                    this.$message({
                        type: 'error',
                        dangerouslyUseHTMLString: true,
                        message: this.$t('messages.failed', {status: this.$t('system.testing.transfer-in.submit')}) + `<div class="mt-2">${response.data.resp_msg.message}</div>`,
                        showClose: true
                    });
                }
            })
        },
    }
}
</script>

<style lang="scss" scoped>

</style>
